<?php
class stat_view_dayControl extends skymvc{
	
	public function __construct(){
		parent::__construct();	
	}
	
	public function onDefault(){
		
	}
	
	public function onAdd(){
		$shopid=get('shopid','i');
		$k=get('k','h');
		$kday=date("Ymd");
		$row=M("stat_view_log")->selectRow("shopid=".$shopid." AND k='".$k."' AND kday='".$kday."' AND userid=".M("login")->userid);
		if(!$row){
			M("stat_view_log")->insert(array(
				"shopid"=>$shopid,
				"k"=>$k,
				"kday"=>$kday,
				"userid"=>M("login")->userid,
				"dateline"=>time(),
				"siteid"=>SITEID
			));
			$d=M("stat_view_day")->selectRow("shopid=".$shopid." AND k='".$k."' AND kday='".$kday."'");
			if($d){
				M("stat_view_day")->update(array(
					"num"=>$d['num']+1
				),"id=".$d['id']);
			}else{
				M("stat_view_day")->insert(array(
					"shopid"=>$shopid,
					"k"=>$k,
					"num"=>1,
					"kday"=>$kday,
					 
					"siteid"=>SITEID
				));
			}
			
		}
		
		echo "console.log('统计成功');";
	}
	
}
?>